package com.view.coach;

import com.action.listBox.ListComboBoxView;
import com.action.table.JTableMainView;
import com.dao.CoachDao;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

public class CoachDelete {
    private JFrame jf=null;
    private JButton submit=new JButton("删除"); //查询
    private JLabel nat=new JLabel("属性");
    private JLabel natV=new JLabel("属性的值");
    private JComboBox nature;   //属性
    private JComboBox natureValue;  //属性值
    private CoachDao cd =new CoachDao();

    public CoachDelete(){
        jf=new JFrame("教练表查询");
        jf.setLayout(null); //绝对定位
        jf.setSize(430,120);
        nat.setSize(30,30);
        natV.setSize(60,30);
        nat.setLocation(20,20);
        natV.setLocation(160,20);
        jf.add(nat);
        jf.add(natV);
        submit.setSize(60,30);
        submit.setLocation(340,20);

        ListComboBoxView nations =  new ListComboBoxView(cd.getNations());
        ListComboBoxView nationsValue=new ListComboBoxView(cd.nationsV("id"));
        nature=nations.getJComboBox();
        nature.setSize(100,30);
        nature.setLocation(50,20);

        natureValue= nationsValue.getJComboBox();
        natureValue.setSize(100,30);
        natureValue.setLocation(220,20);
        final String[] na = {"id"};
        nature.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                //被选定后
                if(e.getStateChange()==ItemEvent.SELECTED){
                    na[0] =nations.getItem();
                    System.out.println(na.length);
                    System.out.println(na[0]);
                    nationsValue.setNations(cd.nationsV(na[0]));
                }
            }
        });
        submit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(e.getSource()==submit){
                    cd.deleteData(nations.getItem(),nationsValue.getItem());
                    //查询，展示查询所有的信息
                    new JTableMainView("教练信息",cd.browsingData());
                }
            }
        });


        jf.add(natureValue);
        jf.add(nature);
        jf.add(submit);
        jf.setVisible(true);
    }
}
